<?php

class Empeval_Methods_Request_GetMyBonusGoals {
	
	/**
	 *
	 * @var App_Methods_Data_App
	 */
	public $app;
	
	public function __construct($params) {
		$this->app = new App_Methods_Data_App($params->app);
	}
	
	public function process() {
		$bonusGoalsForms = EmpevalViewBgfWithSuperiorPositionIdQuery::create()
		->useBonusPeriodsQuery(null, Criteria::LEFT_JOIN)
			->orderByNamePl(Criteria::DESC)
		->endUse()
		->orderByYear(Criteria::DESC)
		->useUsersQuery('Editor', Criteria::LEFT_JOIN)
			->useUserRolesRelatedByToUserIdQuery('EditorUserRoles', Criteria::LEFT_JOIN)
				->leftJoinRoles('EditorRoles')
			->endUse()
			->useUserPositionsQuery('EditorUserPositions', Criteria::LEFT_JOIN)
				->leftJoinPositions('EditorPositions')
			->endUse()
			->addJoinCondition('EditorUserPositions', 'EditorUserPositions.Active = 1')
		->endUse()
		->useUserPositionsRelatedByUserPositionIdQuery()
			->filterByUserId(Empeval_Auth::getInstance()->getInstance()->getUser()->getId())
			->joinPositions()
			->joinUnits()
		->endUse()
		->filterByDeletedDate(null, Criteria::ISNULL)
		->with('BonusPeriods')
		->with('Editor')
		->with('EditorUserRoles')
		->with('EditorRoles')
		->with('EditorUserPositions')
		->with('EditorPositions')
		->with('UserPositionsRelatedByUserPositionId')
		->with('Positions')
		->with('Units')
		->find();
		$bonusPeriods = EmpevalBonusPeriodsQuery::create()->find();
		return new Empeval_Methods_Response_GetMyBonusGoals(true, $bonusGoalsForms, $bonusPeriods);
	}
	
}